package map.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.baidu.mapapi.model.LatLng
import com.baidu.mapapi.search.geocode.GeoCodeResult
import com.baidu.mapapi.search.geocode.OnGetGeoCoderResultListener
import com.baidu.mapapi.search.geocode.ReverseGeoCodeResult
import map.ext.searchManager

/**
 * @author ：zhong.jw
 * @date ：Created in 2022/12/12 13:22
 */
class LoverLocationViewModel : MapBaseViewModel() {

    private val locationInfo = MutableLiveData<ReverseGeoCodeResult>()

    fun getLocationInfo(): LiveData<ReverseGeoCodeResult> = locationInfo


    fun searchLocationInfo(location: LatLng) {
        searchManager().genSearch(location, object : OnGetGeoCoderResultListener {
            override fun onGetGeoCodeResult(p0: GeoCodeResult?) {
            }

            override fun onGetReverseGeoCodeResult(p0: ReverseGeoCodeResult?) {
                p0?.apply {
                    locationInfo.postValue(this)
                }
            }
        })
    }
}